<template>
  <div>
    <pf-table
      ref="pfTable"
      v-model="form"
      class="product-table"
      :columns="columns"
      :form-items="formItems"
      @get-table-data="getTableData"
    />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getProductList } from '@/api/coupon'

export default {
  name: 'ProductList',
  components: {},
  props: {
    siteIds: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      loading: false,
      form: {}
    }
  },
  computed: {
    ...mapGetters([
      'currentEnterprise',
      'currentSite'
    ]),
    formItems() {
      return [
        {
          type: 'input',
          label: '产品名称',
          prop: 'productName'
        }
      ]
    },
    columns() {
      const attrs = { 'min-width': '150px' }
      return [
        { attrs: { type: 'selection' }},
        { label: '产品名称', prop: 'couponName', attrs },
        { label: '产品图片', prop: 'couponName', attrs },
        { label: '价格', prop: 'couponName', attrs },
        { label: '所属门店', prop: 'couponName', attrs }
      ]
    }
  },

  created() {
  },
  methods: {

    getTableData({ pageNo, pageSize, ...formQuery }, done) {
      this.loading = true
      const data = {
        pageNo,
        pageSize,
        industryCode: this.currentSite.industryCode,
        siteIds: this.siteIds,
        ...formQuery
      }
      getProductList(data).then(res => {
        this.loading = false
        done({ data: res.data || [], total: res.count || 0 })
      }).catch(() => {
        done({ data: [], total: 0 })
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .product-table .el-form{
  display: flex;
}
::v-deep .product-table .el-form .el-input{
  width: 240px;
  margin-right: 20px;
}
</style>
